package com.xy.p2p.action.front;



import java.text.DecimalFormat;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.xy.common.util.ErFen;
import com.xy.p2p.model.Tmemberrates;
import com.xy.p2p.service.TfinanceinfoService;
import com.xy.p2p.service.TmemberratesService;



@Controller
public class jsqAction{
	
    //利息计算器
	@RequestMapping("/v_jsq2.jspx")
	public String a(HttpServletRequest request,ModelMap model){
		List<Tmemberrates> list1 = tmemberratesService.getAll();
		model.addAttribute("list1", list1);
		return "/front/xianshi.html";
	}
	@RequestMapping("/v_jsq1.jspx")
	public String b(HttpServletRequest request,ModelMap model){
		int num = Integer.parseInt(request.getParameter("selects"));
		double p = Double.parseDouble(request.getParameter("p"));
		double r = Double.parseDouble(request.getParameter("r"));
		r = r/100;
		int n = Integer.parseInt(request.getParameter("n"));
		if(1==num){
			double payPerMonth = p * r/12 * Math.pow((1 + r/12), n) / (Math.pow((1 + r/12), n) - 1);
			List<Map<String, Double>> list = ErFen.principal(p, r/12, n);
			model.addAttribute("list", list);
			model.addAttribute("p123", p);
			model.addAttribute("r123", r);
			model.addAttribute("n123", n);
			model.addAttribute("payPerMonth", payPerMonth);
			model.addAttribute("opr", "num1");
		}else if(2==num){
			double interestMonth = p*r/12;
			List<Map<String, Double>> list = ErFen.monthly(p, r/12, n);
			model.addAttribute("list", list);
			model.addAttribute("p123", p);
			model.addAttribute("r123", r);
			model.addAttribute("n123", n);
			model.addAttribute("interestMonth",interestMonth);
			model.addAttribute("opr", "num2");
		}
		List<Tmemberrates> list1 = tmemberratesService.getAll();
		model.addAttribute("list1", list1);
		// 设置两位小数点
		DecimalFormat df = new DecimalFormat("0.00");
		Tmemberrates a = tmemberratesService.getFee("management_cost");
		String a1 = df.format(p*a.getRates());
		double x = Double.parseDouble(a1);
		String a2 = df.format(x*n);
		model.addAttribute("a123", a1);
		model.addAttribute("a222",a2);
		return "/front/xianshi.html";
		
	}
	@Resource
	private TmemberratesService tmemberratesService;
	@Resource
	private TfinanceinfoService tfinanceinfoService;

}